RM := @$(RM)
AUTO_MK := $(foreach dir, $(filter %/, $(objs)), $(shell pwd)/$(dir).auto.mk)
INCLUDE := $(foreach dir, $(filter %/, $(objs)), -I$(shell pwd)/$(dir)) -I$(shell pwd)
deps := $(patsubst %.o, %.d, $(filter %.o, $(objs)))
objs := $(patsubst %/, %/built-in.o, $(objs))

CLEAN := None

CFLAGS += $(INCLUDE)
CFLAGS += $(foreach libdir, $(LIBDIRS), -L$(libdir))
CFLAGS += $(foreach lib, $(LIBS), -l$(lib))

CCFLAGS+= $(CFLAGS)

built-in.o:
None:

%/.auto.mk:
	@echo include Makefile >> $@
	@echo include $(DEP_MK_PATH) >> $@
# 为了能够往下递归
clean:$(filter %/built-in.o, $(objs))

%/built-in.o:$(CLEAN) $(AUTO_MK)
	@make $(MAKECMDGOALS) -C $(patsubst %/built-in.o, %/, $@) -f .auto.mk --no-print-directory  

%.o:%.c
	@$(CC) -c -Wall $(CFLAGS) $< -o $@ -MMD -MF $*.d -MP
	@echo $(CC) $@

built-in.o:$(objs)
	@$(LD) -r -o $@ $(objs)
	@echo $(LD) $(objs)

-include $(deps)
.PHONY:clean
clean:
	@echo "clean $(shell pwd)"
	$(RM) *.o
	$(RM) *.d
	-$(RM) *.o $(name)
